package com.jic.market.mapper.coupon;

import com.jic.market.entity.coupon.CouponDetail;

import com.jic.market.response.rest.coupon.QueryCouponPersonResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 优惠券明细表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-16 05:05:22
 */
@Repository
public interface CouponDetailMapper {

    long insert(CouponDetail couponDetail);

    long delete(Long id);

    long update(CouponDetail couponDetail);

    CouponDetail queryByPrimaryKey(Long id);

    List<CouponDetail> query(CouponDetail couponDetail);

    List<CouponDetail> queryPage(@Param("startIndex") int startIndex,
                                 @Param("limit") int limit,
                                 @Param("couponDetail") CouponDetail couponDetail,
                                 @Param("createStartTime") Date createStartTime,
                                 @Param("createEndTime") Date createEndTime,
                                 @Param("useStartTime") Date useStartTime,
                                 @Param("useEndTime") Date useEndTime);

    long queryPageCount(@Param("couponDetail") CouponDetail couponDetail,
                        @Param("createStartTime") Date createStartTime,
                        @Param("createEndTime") Date createEndTime,
                        @Param("useStartTime") Date useStartTime,
                        @Param("useEndTime") Date useEndTime);

    @Update("update market_coupon_detail set status='4' where coupon_code=#{couponCode} and delete_flag='0'")
    long invalidCouponDetail(@Param("couponCode") String promotionId);


    Long queryTotalByPromotionId(@Param("promotionId") String promotionId , @Param("businessId") Long businessId);

    Long queryLimitDayNumByThirdUserId(@Param("thirdUserId") String thirdUserId, @Param("promotionId") String promotionId, @Param("businessId") Long businessId);

    Long queryLimitNumByThirdUserId(@Param("thirdUserId") String thirdUserId, @Param("promotionId") String promotionId, @Param("businessId") Long businessId);


    List<QueryCouponPersonResponse> queryPageDetail(@Param("start") Integer start, @Param("limit") Integer limit, @Param("status") String status, @Param("thirdUserId") String thirdUserId,@Param("businessId") Long businessId);

    Long queryPageDetailTotal(@Param("status") String status, @Param("thirdUserId") String thirdUserId,@Param("businessId") Long businessId);

    List<QueryCouponPersonResponse> queryMyCouponList(@Param("thirdUserId") String thirdUserId);

    long updateStatus(@Param("couponCodes") List<String> couponCodes, @Param("status") Integer status);

    List<CouponDetail> queryCouponByPromotionId(@Param("promotionId") String promotionId);

    void foreachInsert(List<CouponDetail> partition);

    Long queryMyCouponCount(@Param("userId") String userId);

    List<CouponDetail> queryCouponExpired();

    void bacthCouponExpiredStatus(@Param("couponIds") List<Long> couponIds, @Param("noticeStatus") Integer status);
}